package com.android.cookbook.activity;

import java.io.IOException;

import com.android.cookbook.R;
import com.android.cookbook.R.id;
import com.android.cookbook.R.layout;
import com.android.cookbook.R.menu;
import com.android.cookbook.adapter.ImageAdapter;
import com.android.cookbook.db.BaseDatosHelper;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

public class CookBookActivity extends Activity {
	
	GridView grid_main;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        grid_main = (GridView)findViewById(R.id.GridViewIni);  
        grid_main.setAdapter(new ImageAdapter(this));  

        ImageView create = (ImageView) findViewById(R.id.create_main);
    
        create.setOnClickListener(new View.OnClickListener() {             
        	public void onClick(View view) {                   
        		Intent myIntentCreate = new Intent(view.getContext(),RecipeCreate.class);
            	startActivityForResult(myIntentCreate, 0);             
        	}          
        });
        
        ImageView search = (ImageView)findViewById(R.id.search_main);
        
        search.setOnClickListener(new View.OnClickListener() {             
        	public void onClick(View view) {
            	Intent myIntent = new Intent(view.getContext(),RecipeSearch.class);
            	startActivityForResult(myIntent, 0);            
        	}          
        });        
    }
    
    public boolean onCreateOptionsMenu(Menu menu){
        MenuInflater inflater=getMenuInflater(); 
        inflater.inflate(R.menu.menu,menu); 
        return true; 
    }

    public boolean onOptionsItemSelected (MenuItem item){
    	Intent myIntent;
        switch (item.getItemId()){ 
            case R.id.menu_search: 
            	myIntent = new Intent(this,RecipeSearch.class);
            	startActivityForResult(myIntent, 0);
            	return true;
            case R.id.menu_create: 
            	myIntent = new Intent(this,RecipeCreate.class);
            	startActivityForResult(myIntent, 0);
                return true;            
        }
        return super.onOptionsItemSelected(item);
    }
    
/*    @Override
    public void onBackPressed(){
    	AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    	builder.setMessage("Are you sure you want to exit?") 
    	       .setCancelable(false) 
    	       .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
    	           public void onClick(DialogInterface dialog, int id) { 
    	        	   this.finish(); 
    	           } 
    	       }) 
    	       .setNegativeButton("No", new DialogInterface.OnClickListener() { 
    	           public void onClick(DialogInterface dialog, int id) { 
    	                dialog.cancel(); 
    	           } 
    	       }); 
    	AlertDialog alert = builder.create();
    	alert.show();
    }*/
 
}